﻿using CleanArchitecture.Infrastructure.Entities.Business;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CleanArchitecture.Infrastructure.DataMapping.Business
{
    /// <summary>
    /// Represents a permission record-customer role mapping configuration
    /// </summary>
    public partial class AdminRoleBusColumnMappingMap : NowaEntityTypeConfiguration<AdminRoleBusColumnMapping>
    {
        #region Methods

        /// <summary>
        /// Configures the entity
        /// </summary>
        /// <param name="builder">The builder to be used to configure the entity</param>
        public override void Configure(EntityTypeBuilder<AdminRoleBusColumnMapping> builder)
        {
            builder.ToTable("adminrole_buscolumn_mapping");
            builder.HasKey(mapping => new { mapping.FKAdminRoleId, mapping.FKColumnId });

            builder.Property(mapping => mapping.FKAdminRoleId).HasColumnName("FK_AdminRole_Id");
            builder.Property(mapping => mapping.FKColumnId).HasColumnName("FK_BusColumn_Id");
            builder.Property(mapping => mapping.AssignedButtonIds).HasMaxLength(500);
            builder.Property(mapping => mapping.IsAllow).IsRequired();
            builder.Property(mapping => mapping.AuthorizedButtonIds).HasMaxLength(500);
            builder.HasOne(mapping => mapping.AdminRole)
                .WithMany(role => role.AdminroleBusinessColumnMappings)
                .HasForeignKey(mapping => mapping.FKAdminRoleId)
                .IsRequired();

            builder.HasOne(mapping => mapping.Column)
                .WithMany(record => record.AdminroleBusinessColumnMappings)
                .HasForeignKey(mapping => mapping.FKColumnId)
                .IsRequired();

            builder.Ignore(mapping => mapping.Id);

            base.Configure(builder);
        }

        #endregion
    }
}
